import { getChannelAPI } from "@/api/channel"
import type { ChannelItem } from "@/types"
import { onMounted, ref } from "vue"

// 负责对频道的数据 和 方法进行提供
export const useChannel = () => {
    const channelList = ref<ChannelItem[]>([])
    // 激活id
    const activeId = ref(0)
    // 如果最终这个函数在组件中 作用还在组件中
    onMounted(() => {
        getChannel()
    })
    const getChannel = async () => {
        const result = await getChannelAPI()
        channelList.value = result.channels // 赋值列表
        activeId.value = result.channels[0].id // 把第一个频道的id作为激活的选项
    }

    return { channelList, activeId }

}